﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Restaurant.DAO
{

    public class HanThanhToanDB
    {
        private SqlConnection conn = KetNoiDB.TaoKetNoi();

        public DataTable LayHanThanhToan()
        {
            try
            {

                conn.Open();
                string strCmd = "dbo.spLoadHanThanhToan";
                SqlCommand cmd = new SqlCommand(strCmd, conn);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                DataTable dbtab = new DataTable();
                adapt.Fill(dbtab);
                conn.Close();
                return dbtab;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public DataTable LayHanThanhToan(int ma)
        {
            try
            {

                conn.Open();
                string strCmd = "dbo.spLayHanThanhToanTheoMa";
                SqlCommand cmd = new SqlCommand(strCmd, conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@ma", ma));
                SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                DataTable dbtab = new DataTable();
                adapt.Fill(dbtab);
                conn.Close();
                return dbtab;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public DataTable LayHinhThucThanhToan()
        {
            try
            {
                conn.Open();
                string strCmd = "dbo.spLoadHinhThucThanhToan";
                SqlCommand cmd = new SqlCommand(strCmd, conn);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                DataTable dbtab = new DataTable();
                adapt.Fill(dbtab);
                conn.Close();
                return dbtab;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public DataTable LayHinhThucThanhToan(int ma)
        {
            try
            {

                conn.Open();
                string strCmd = "dbo.spLayHinhThanhToanTheoMa";
                SqlCommand cmd = new SqlCommand(strCmd, conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@ma", ma));
                SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                DataTable dbtab = new DataTable();
                adapt.Fill(dbtab);
                conn.Close();
                return dbtab;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public bool ThemHanThanhToan(string tenhtt)
        {
            try
            {

                conn.Open();
                string strCmd = "dbo.spThemHanThanhToan";
                SqlCommand cmd = new SqlCommand(strCmd, conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@ten", tenhtt));
                SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                DataTable dbtab = new DataTable();
                adapt.Fill(dbtab);
                conn.Close();
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public bool SuaHanThanhToan(int ma,string ten)
        {
            try
            {

                conn.Open();
                string strCmd = "dbo.spSuaHanThanhToan";
                SqlCommand cmd = new SqlCommand(strCmd, conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@ma", ma));
                cmd.Parameters.Add(new SqlParameter("@ten", ten));
                SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                DataTable dbtab = new DataTable();
                adapt.Fill(dbtab);
                conn.Close();
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public bool ThemHinhThucThanhToan(string tenhttt)
        {
            try
            {

                conn.Open();
                string strCmd = "dbo.spThemHinhThucThanhToan";
                SqlCommand cmd = new SqlCommand(strCmd, conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@ten", tenhttt));
                SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                DataTable dbtab = new DataTable();
                adapt.Fill(dbtab);
                conn.Close();
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public bool SuaHinhThucThanhToan(int ma,string ten)
        {
            try
            {

                conn.Open();
                string strCmd = "dbo.spSuaHinhThucThanhToan";
                SqlCommand cmd = new SqlCommand(strCmd, conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@ma", ma));
                cmd.Parameters.Add(new SqlParameter("@ten", ten));
                SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                DataTable dbtab = new DataTable();
                adapt.Fill(dbtab);
                conn.Close();
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public bool XoaHanThanhToan(int ma)
        {
            try
            {

                conn.Open();
                string strCmd = "dbo.spXoaHanThanhToan";
                SqlCommand cmd = new SqlCommand(strCmd, conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@ma", ma));
                SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                DataTable dbtab = new DataTable();
                adapt.Fill(dbtab);
                conn.Close();
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public bool XoaHinhThucThanhToan(int ma)
        {
            try
            {

                conn.Open();
                string strCmd = "dbo.spXoaHinhThucThanhToan";
                SqlCommand cmd = new SqlCommand(strCmd, conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@ma", ma));
                SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                DataTable dbtab = new DataTable();
                adapt.Fill(dbtab);
                conn.Close();
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
